import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { LoginPage } from '../login/login';
import { TabsPage } from "../tabs/tabs";
import { registerOptions } from '../../interfaces/register-info';
import { HttpServiceProvider } from '../../providers/http-service/http-service';
/**
 * Generated class for the SignupPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-signup',
  templateUrl: 'signup.html',
})
export class SignupPage {


  data: any;

  getVcode:boolean=false;
  
  register_data: registerOptions = { account: '', name: '', password: '', captcha:'' };


  constructor(public navCtrl: NavController, public navParams: NavParams,private httpServiceProvider: HttpServiceProvider) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad SignupPage');
  }
/**
 *
 */
  GoToLogin() {
    this.navCtrl.push(TabsPage);
  }
  /**
   *
   * @param phone_no
   */
  public getCode(phone_no: HTMLInputElement) {

    this.httpServiceProvider.getVerCode(phone_no.value).then((result) => {
        this.data = result;
        console.log(this.data);
        if(this.data.code==1)
        {
          console.log("---验证码请求成功");
        }
      }, (err) => {
        console.log(err);
    });
  }
  /**
   *
   * @param phone_no
   * @param vcode
   * @param password
   */
  public SignupSubmit(phone_no: HTMLInputElement,name: HTMLInputElement,vcode: HTMLInputElement,password: HTMLInputElement) {

    this.register_data.account=phone_no.value;
    this.register_data.name=name.value;
    this.register_data.password=password.value;
    this.register_data.captcha=vcode.value;   

    this.httpServiceProvider.register(this.register_data).then((result) => {

      this.data = result;
      console.log(this.data);
      if(this.data.code==1)
      {
        console.log("---注册成功");
        this.GoToLogin();
      }
    }, (err) => {

      console.log(err);

    });

  }

}
